var lunboImgesUrl = "";
var type;
var imageUrlList;


init();

function init() {
    type = getType();
    imageUrlList = window.opener.imageUrlList;
    //状态（false代表非退回修改，true代表退回修改）
    var status = window.opener.addStatus;
    if(!status || status == false || status == "false"){
        //其他情况下
        $("#update").show();
        $("#close").show();
    }else{
        //退回修改情况下
        $("#update").hide();
        $("#close").hide();
        $("#desc").hide();
        $("#style").hide();
    }

    var list = imageUrlList[type - 1];
    var imageUrls = "";

    if(list.length > 0 ){
        for(var i=0; i<list.length; i++){
            imageUrls = imageUrls + list[i].imgUrl + ",";
        }
        getLunBo(imageUrls,status);
    }
}


function save(){
    window.close();
    window.opener.getImgUrl(lunboImgesUrl,type);
}

//获取类型
function getType() {
    var Request = new Object();
    Request = GetRequest();
    return Request['type'];
}

function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

function getLunBo(lunboImgUrl,nowAuditState) {
    lunboImgesUrl = lunboImgUrl;

    var lunboImgList = lunboImgUrl.split(",");

    lunboHtml = "";
    for (var i = 0; i < lunboImgList.length - 1; i++) {
        var imgUrl = "";
        if (lunboImgList[i] != null && lunboImgList[i].indexOf("/") != -1) {
            imgUrl = lunboImgList[i].split("/");
            imgUrl = imgUrl[imgUrl.length - 1];
        }
        lunboHtml = lunboHtml
            + '<section class="up-section fl">';
            if(!nowAuditState || nowAuditState == false || nowAuditState == "false"){
            //退回修改情况下
                lunboHtml = lunboHtml
                + '<img class="close-upimg" name="img" src="img/a7.png">';
            }
        lunboHtml = lunboHtml
            + '<img class="up-img" name="img" src="'
            + lunboImgList[i]
            + '" onclick="maxImg(this)">'
            + '<p class="img-name-p">'
            + imgUrl
            + '</p><input id="taglocation" name="taglocation" value="" type="hidden">'
            + '<input id="tags" name="tags" value="" type="hidden">'
            + '</section>';
    }
    if(!nowAuditState || nowAuditState == false || nowAuditState == "false"){
        //退回修改情况下
        lunboHtml = lunboHtml
            + '<section class="z_file fl">'
            + '<img src="img/a11.png" class="add-img">'
            + '<input type="file" name="file" id="file" class="file" value="" accept="image/jpg,image/jpeg,image/png,image/bmp" multiple />'
            + '</section>';
    }
    $("#lunbo").html(lunboHtml);
}

function windowClose(){
    window.close();
}

function maxImg(img){
    var flag = true,//状态true为正常的状态,false为放大的状态
        imgH,//图片的高度
        imgW;//图片的宽度

    imgH = img.height; //获取图片的高度
    imgW = img.width; //获取图片的宽度
    if(flag){
        //图片为正常状态,设置图片宽高为现在宽高的2倍
        flag = false;//把状态设为放大状态
        img.height = imgH*2;
        img.width = imgW*2;
    }else{
        //图片为放大状态,设置图片宽高为现在宽高的二分之一
        flag = true;//把状态设为正常状态
        img.height = imgH/2;
        img.width = imgW/2;
    }
    $("#imgShow").attr("src", img.src).show();
}

function imgHide(){
    $("#imgShow").hide();
}